% *********************************************************************
% CPDEETES.STY
% ADAPTACAO DO ARQUIVO SFTUTHESIS.STY
%
% LEANDRO PESSOA - 1998
% *********************************************************************

% Simon Fraser University Thesis style -- hacked by Stephen Chan (css) from:
% Stanford University PhD thesis style -- modifications to the report style
% (Further hacked by Margaret. Sharon SFU ACS)
%
\typeout{Document Style Option 'sfuthesis' -- April 1996, version 1.1 (ACS)}
\makeatletter
\oddsidemargin 3.8cm\advance\oddsidemargin by -1in
\evensidemargin 3.8cm\advance\evensidemargin by -1in
\if@twoside
   \advance\evensidemargin by -1.3cm
\fi  % Adjust evensidemargin if twoside option specified **MS**
\textwidth 8.5in\advance\textwidth by -3.8cm\advance\textwidth by -2.5cm
\topmargin 1in\advance\topmargin by -2.5cm
\headsep 2.5cm
\textheight 11in
\advance\textheight by -5cm % To account for header and TeX's top margin
\advance\textheight by -2.5cm % Bottom margin
\marginparwidth 40pt \marginparsep 10pt
\brokenpenalty=10000
\renewcommand{\baselinestretch}{1.3}
\def\@xfloat#1[#2]{\ifhmode \@bsphack\@floatpenalty -\@Mii\else
   \@floatpenalty-\@Miii\fi\def\@captype{#1}\ifinner
      \@parmoderr\@floatpenalty\z@
    \else\@next\@currbox\@freelist{\@tempcnta\csname ftype@#1\endcsname
       \multiply\@tempcnta\@xxxii\advance\@tempcnta\sixt@@n
       \@tfor \@tempa :=#2\do
                        {\if\@tempa h\advance\@tempcnta \@ne\fi
                         \if\@tempa t\advance\@tempcnta \tw@\fi
                         \if\@tempa b\advance\@tempcnta 4\relax\fi
                         \if\@tempa p\advance\@tempcnta 8\relax\fi
         }\global\count\@currbox\@tempcnta}\@fltovf\fi
    \global\setbox\@currbox\vbox\bgroup 
    \def\baselinestretch{1}\@normalsize
    \boxmaxdepth\z@
    \hsize\columnwidth \@parboxrestore}
\long\def\@footnotetext#1{\insert\footins{\def\baselinestretch{1}\footnotesize
    \interlinepenalty\interfootnotelinepenalty 
    \splittopskip\footnotesep
    \splitmaxdepth \dp\strutbox \floatingpenalty \@MM
    \hsize\columnwidth \@parboxrestore
   \edef\@currentlabel{\csname p@footnote\endcsname\@thefnmark}\@makefntext
    {\rule{\z@}{\footnotesep}\ignorespaces
      #1\strut}}}
\def\@title{}
\def\@author{}
\newsavebox{\@qual}
\newif\ifqvoid
\qvoidtrue
\def\@qualifications#1{\ifqvoid
			\sbox{\@qual}{\parbox{\textwidth}
				{\begin{center}\@author\\\end{center}}}
			\qvoidfalse
			\fi
			\sbox{\@qual}{\parbox{\textwidth}
				{\begin{center}\usebox{\@qual}\\{#1}\end{center}}}
		       }
\def\apresentacapa#1{\gdef\@apresentacapa{#1}}
\def\@apresentacapa{-------------------------}

\def\subtitle#1{\gdef\@subtitle{#1}}
\def\@subtitle{-----}

\gdef\qualification#1{\@qualifications{#1}}
\def\entity#1{\gdef\@entity{#1}}
\def\@entity{Centro de Pesquisa e Desenvolvimento em Engenharia El\'{e}trica}
\def\dept#1{\gdef\@dept{#1}}
\def\@dept{Computing Science}
\def\degree#1{\gdef\@degree{#1}}
\def\@degree{Master of Science}
\def\endeavour#1{\gdef\@endeavour{#1}}
\def\@endeavour{thesis}
\def\submitdate#1{\gdef\@submitdate{#1}}
\def\@submitdate{\ifcase\the\month\or
  January\or February\or March\or April\or May\or June\or
  July\or August\or September\or October\or November\or December\fi
  \space \number\the\year}
\def\copyrightyear#1{\gdef\@copyrightyear{#1}} % \author, \title in report
\def\@copyrightyear{\space\number\the\year}
\def\chair#1{\gdef\@chair{#1}}
\newif\ifcontentspage
\contentspagetrue 
\newif\iffigurespage \newif\iftablespage
\figurespagefalse \tablespagefalse

%\long\def\@makecaption#1#2{%
%   \vskip 10\p@
%     {\reset@font\small{\bf #1.} #2\par}}

% LEANDRO - formatacao do caption
\long\def\@makecaption#1#2{%
  \vskip\abovecaptionskip
%  \sbox\@tempboxa{#1: #2}%
  \sbox\@tempboxa{\reset@font\footnotesize{\bf #1.} #2\par}%
  \ifdim \wd\@tempboxa >\hsize
    {\reset@font\footnotesize{\bf #1.} #2\par}
%    #1: #2\par
  \else
    \global \@minipagefalse
    \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
  \fi
  \vskip\belowcaptionskip}

% For other lists eg, maps, abbreviations **MS**
\newif\ifotherlistpage \otherlistpagefalse
\def\@otherlist{ %  Call user's macro \otherlist **MS** 
	\otherlist
	}

	\def\titlep{
	\thispagestyle{empty}%
	\begingroup
	\null\vskip .5in 
	\typeout{Title & approval pages.}
	\begin{center}
		{\LARGE\uppercase\expandafter{\bf \@title}}
	\end{center}
	\begin{center}
		{\Large\expandafter{\bf \@subtitle}}
	\end{center}
	%\vskip.5in
	\begin{center}
		%\rm por:\\
	\end{center}
	\usebox{\@qual}
	\vfill
	\begin{center}
		 {\small\sc
             \expandafter{\@apresentacapa}\\
%             Disserta\c{c}\~{a}o submetida \`{a} Banca Examinadora\\
%             designada pelo Colegiado do Programa de P\'{o}s-\\
%             gradua\c{c}\~{a}o em Engenharia El\'{e}trica da\\
%             Universidade Federal de Minas Gerais, como requisito\\
%             parcial \`{a} obten\c{c}\~{a}o do t\'{\i}tulo de\\
             \expandafter{\@degree}\\
%		 a \@endeavour\  submitted in partial fulfillment\\
%		 of the requirements for the degree of\\
%		 \expandafter{\@degree}\\
		 }
%		in the \expandafter{\@entity}\\
%		of\\
%            {\sc	
%          \expandafter{\@dept}\\
%            \expandafter{\@entity}\\
%            }
            \vskip1.5cm\vfill
            \'{A}rea de Concentra\c{c}\~{a}o: Autom\'{a}tica\\
            Linha de Pesquisa: \expandafter{\@dept}\\
            Orientador: \@chair\\
	\end{center}
	\vskip.25in\vfill
	\begin{center}
		\copyright\ \@author\ \@copyrightyear\\
             {\sc \expandafter{\@entity}}\\
		 UNIVERSIDADE FEDERAL DE MINAS GERAIS\\
		\@submitdate\\
	\end{center}
%	\vskip.5in
%	\begin{center}
%	\small
%	All rights reserved. This work may not be\\
%	reproduced in whole or in part, by photocopy\\
%	or other means, without the permission of the author.
%	\end{center}
	\endgroup
	\newpage}
\def\apdesclabel#1{\hspace\labelsep \bf #1:\hfill}
\def\apdesc{\list{}{\leftmargin\apdescmargin
\labelwidth\leftmargin \advance\labelwidth -\labelsep
\let\makelabel\apdesclabel}}
\let\endapdesc\endlist
\newdimen\apdescmargin
\apdescmargin=2in

\newsavebox{\@apitems}
\def\@approvalitem#1{
		\sbox{\@apitems}{\begin{minipage}[t]{3.5in}\parindent=0pt
		\usebox{\@apitems}
		\vspace{.25in}\\ 
		\vrule width3.5in height 0.4pt\\
		#1
		\end{minipage}
		}
}
\gdef\approvalitem#1{\@approvalitem{#1}}

\def\approvalpage{% 
	\begingroup
	\begin{center}
		{\large\bf APPROVAL}
	\end{center}
	\vskip.25in
	\begin{apdesc}
		\let\\\ % turn off the user specified line breaking.
		\item[Name] \@author
		\item[Degree] \@degree
		\item[Title of \@endeavour] \@title
	\end{apdesc}
	\vskip.25in 
	\begin{apdesc}
	\item[Examining Committee]\par\@chair\\Chair\\	
	\usebox{\@apitems}
	\end{apdesc}
	\vskip.25in 
	\vfill
	\begin{apdesc}
	\item[Date Approved] \ \hrulefill\ 
	\end{apdesc}
	\endgroup
	\vfil
	\advance\textheight by -.5in 
		% Else first preface's page number too low **MS**
	\newpage
}

\def\beforepreface{
	\pagenumbering{roman}
	\pagestyle{plain}
	\headsep 0in
	\advance\textheight by .5in
	\titlep
%	\approvalpage
	\headsep .5in
	}

\def\prefacesection#1{
	\typeout{Front matter: #1.}
	\chapter*{#1}
	\addcontentsline{toc}{chapter}{#1}
	}

\def\afterpreface{
	\ifcontentspage
		\newpage
		\tableofcontents
		\newpage
	\fi
	\iftablespage
		{\addvspace{10pt}
		\addcontentsline{toc}{chapter}{Lista de Tabelas}
	  	\listoftables
		}
		\newpage
	\fi
	\iffigurespage
		{\addvspace{10pt}
		\addcontentsline{toc}{chapter}{Lista de Figuras}
		\listoffigures
		}
		\newpage
	\fi
	\ifotherlistpage
		{\addvspace{10pt}
		\@otherlist
		}
		\newpage
	\fi
	\pagenumbering{arabic}
	\pagestyle{headings}
	}

\pagestyle{headings}
\def\l@chapter{\@dottedtocline{0}{1.5em}{2.3em}}
\def\l@section{\@dottedtocline{1}{3.8em}{3.2em}}
\def\l@subsection{\@dottedtocline{2}{7.0em}{4.1em}}
		% All entries in toc need dotted lines   **MS**

\newif\ifappendices\appendicesfalse
\newif\iffirstappendix\firstappendixtrue

\def\appendix#1{
	\ifappendices
		\iffirstappendix
			\setcounter{chapter}{0}
			\setcounter{section}{0}
			\def\@chapapp{Ap\^{e}ndice}
 			\def\thechapter{\Alph{chapter}}
			\addtocontents{toc}{Ap\^{e}ndices}
			\typeout{Ap\^{e}ndices.}
			\firstappendixfalse
		\fi
		\chapter{#1}
	\else
		\chapter*{Ap\^{e}ndice: #1}
		\addcontentsline{toc}{chapter}{Ap\^{e}ndice: #1}
		\typeout{Ap\^{e}ndice.}
	\fi 
	}

\def\enoteformat{\rightskip\z@ \leftskip\z@ \parindent=1.8em
     \leavevmode\textindent{\@theenmark.}}
\def\enotesize{\normalsize}
\def\notesname{}

\def\printendnotes{
	\typeout{Endnotes for chapter \thechapter.}
	\chapter*{Notes for Chapter \thechapter}
	\addcontentsline{toc}{section}{Notes for Chapter \thechapter}
	\begingroup
		\parskip 2ex
		\theendnotes
	\endgroup
	\setcounter{endnote}{0}
}

\def\printallendnotes{
	\typeout{Endnotes.}
	\chapter*{Notes}
	\addcontentsline{toc}{chapter}{Notes}
	\begingroup
		\parskip 2ex
		\theendnotes
	\endgroup
}
\makeatother
